<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.8"/>
<title>AndBase开发框架: com.ab.network.toolbox.ByteArrayPool类 参考</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="ic_launcher.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">AndBase开发框架
   &#160;<span id="projectnumber">1.6</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.8 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="pages.html"><span>相关页面</span></a></li>
      <li><a href="namespaces.html"><span>命名空间</span></a></li>
      <li class="current"><a href="annotated.html"><span>类</span></a></li>
      <li><a href="files.html"><span>文件</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="搜索" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>类列表</span></a></li>
      <li><a href="classes.html"><span>类索引</span></a></li>
      <li><a href="hierarchy.html"><span>类继承关系</span></a></li>
      <li><a href="functions.html"><span>类成员</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>全部</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>类</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>命名空间</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>文件</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>函数</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>变量</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>枚举值</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>页</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="namespacecom.html">com</a></li><li class="navelem"><a class="el" href="namespacecom_1_1ab.html">ab</a></li><li class="navelem"><a class="el" href="namespacecom_1_1ab_1_1network.html">network</a></li><li class="navelem"><a class="el" href="namespacecom_1_1ab_1_1network_1_1toolbox.html">toolbox</a></li><li class="navelem"><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html">ByteArrayPool</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public 成员函数</a> &#124;
<a href="#pro-static-attribs">静态 Protected 属性</a> &#124;
<a href="#pri-methods">Private 成员函数</a> &#124;
<a href="#pri-attribs">Private 属性</a> &#124;
<a href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool-members.html">所有成员列表</a>  </div>
  <div class="headertitle">
<div class="title">com.ab.network.toolbox.ByteArrayPool类 参考</div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public 成员函数</h2></td></tr>
<tr class="memitem:ac01f6816fbb12d7761949ad75627b336"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html#ac01f6816fbb12d7761949ad75627b336">ByteArrayPool</a> (int sizeLimit)</td></tr>
<tr class="separator:ac01f6816fbb12d7761949ad75627b336"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a39728ad02dfe392e06e66a0e6a93a290"><td class="memItemLeft" align="right" valign="top">synchronized byte[]&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html#a39728ad02dfe392e06e66a0e6a93a290">getBuf</a> (int len)</td></tr>
<tr class="separator:a39728ad02dfe392e06e66a0e6a93a290"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:add6bf677a419e1220b4c41dfb6d68797"><td class="memItemLeft" align="right" valign="top">synchronized void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html#add6bf677a419e1220b4c41dfb6d68797">returnBuf</a> (byte[] buf)</td></tr>
<tr class="separator:add6bf677a419e1220b4c41dfb6d68797"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pro-static-attribs"></a>
静态 Protected 属性</h2></td></tr>
<tr class="memitem:a9bdaaa2755b4025575e1011576c6a197"><td class="memItemLeft" align="right" valign="top">static final Comparator&lt; byte[]&gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html#a9bdaaa2755b4025575e1011576c6a197">BUF_COMPARATOR</a></td></tr>
<tr class="separator:a9bdaaa2755b4025575e1011576c6a197"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pri-methods"></a>
Private 成员函数</h2></td></tr>
<tr class="memitem:a7d48903ff5a1c3c8034ed29088f46f61"><td class="memItemLeft" align="right" valign="top">synchronized void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html#a7d48903ff5a1c3c8034ed29088f46f61">trim</a> ()</td></tr>
<tr class="separator:a7d48903ff5a1c3c8034ed29088f46f61"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pri-attribs"></a>
Private 属性</h2></td></tr>
<tr class="memitem:abd8cd0d7462fc886099b2a1f4d8dd511"><td class="memItemLeft" align="right" valign="top">List&lt; byte[]&gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html#abd8cd0d7462fc886099b2a1f4d8dd511">mBuffersByLastUse</a> = new LinkedList&lt;byte[]&gt;()</td></tr>
<tr class="separator:abd8cd0d7462fc886099b2a1f4d8dd511"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0b590097699829dea81659bf28ed5242"><td class="memItemLeft" align="right" valign="top">List&lt; byte[]&gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html#a0b590097699829dea81659bf28ed5242">mBuffersBySize</a> = new ArrayList&lt;byte[]&gt;(64)</td></tr>
<tr class="separator:a0b590097699829dea81659bf28ed5242"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6e248b56d65802325d2208ea3e0dbef3"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html#a6e248b56d65802325d2208ea3e0dbef3">mCurrentSize</a> = 0</td></tr>
<tr class="separator:a6e248b56d65802325d2208ea3e0dbef3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a635c9ca5b29a0ce5f3ad8b6aadefec5e"><td class="memItemLeft" align="right" valign="top">final int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html#a635c9ca5b29a0ce5f3ad8b6aadefec5e">mSizeLimit</a></td></tr>
<tr class="separator:a635c9ca5b29a0ce5f3ad8b6aadefec5e"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">详细描述</h2>
<div class="textblock"><p><a class="el" href="classcom_1_1ab_1_1network_1_1toolbox_1_1_byte_array_pool.html">ByteArrayPool</a> is a source and repository of <code>byte[]</code> objects. Its purpose is to supply those buffers to consumers who need to use them for a short period of time and then dispose of them. Simply creating and disposing such buffers in the conventional manner can considerable heap churn and garbage collection delays on Android, which lacks good management of short-lived heap objects. It may be advantageous to trade off some memory in the form of a permanently allocated pool of buffers in order to gain heap performance improvements; that is what this class does. </p>
<p>A good candidate user for this class is something like an I/O system that uses large temporary <code>byte[]</code> buffers to copy data around. In these use cases, often the consumer wants the buffer to be a certain minimum size to ensure good performance (e.g. when copying data chunks off of a stream), but doesn't mind if the buffer is larger than the minimum. Taking this into account and also to maximize the odds of being able to reuse a recycled buffer, this class is free to return buffers larger than the requested size. The caller needs to be able to gracefully deal with getting buffers any size over the minimum. </p>
<p>If there is not a suitably-sized buffer in its recycling pool when a buffer is requested, this class will allocate a new buffer and return it. </p>
<p>This class has no special ownership of buffers it creates; the caller is free to take a buffer it receives from this pool, use it permanently, and never return it to the pool; additionally, it is not harmful to return to this pool a buffer that was allocated elsewhere, provided there are no other lingering references to it. </p>
<p>This class ensures that the total size of the buffers in its recycling pool never exceeds a certain byte limit. When a buffer is returned that would cause the pool to exceed the limit, least-recently-used buffers are disposed. </p>
</div><h2 class="groupheader">构造及析构函数说明</h2>
<a class="anchor" id="ac01f6816fbb12d7761949ad75627b336"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">com.ab.network.toolbox.ByteArrayPool.ByteArrayPool </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>sizeLimit</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">sizeLimit</td><td>the maximum size of the pool, in bytes </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<h2 class="groupheader">成员函数说明</h2>
<a class="anchor" id="a39728ad02dfe392e06e66a0e6a93a290"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">synchronized byte [] com.ab.network.toolbox.ByteArrayPool.getBuf </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>len</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Returns a buffer from the pool if one is available in the requested size, or allocates a new one if a pooled one is not available.</p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">len</td><td>the minimum size, in bytes, of the requested buffer. The returned buffer may be larger. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>返回</dt><dd>a byte[] buffer is always returned. </dd></dl>

</div>
</div>
<a class="anchor" id="add6bf677a419e1220b4c41dfb6d68797"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">synchronized void com.ab.network.toolbox.ByteArrayPool.returnBuf </td>
          <td>(</td>
          <td class="paramtype">byte[]&#160;</td>
          <td class="paramname"><em>buf</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Returns a buffer to the pool, throwing away old buffers if the pool would exceed its allotted size.</p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">buf</td><td>the buffer to return to the pool. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a class="anchor" id="a7d48903ff5a1c3c8034ed29088f46f61"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">synchronized void com.ab.network.toolbox.ByteArrayPool.trim </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Removes buffers from the pool until it is under its size limit. </p>

</div>
</div>
<h2 class="groupheader">类成员变量说明</h2>
<a class="anchor" id="a9bdaaa2755b4025575e1011576c6a197"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">final Comparator&lt;byte[]&gt; com.ab.network.toolbox.ByteArrayPool.BUF_COMPARATOR</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span><span class="mlabel">protected</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<b>初始值:</b><div class="fragment"><div class="line">= <span class="keyword">new</span> Comparator&lt;byte[]&gt;() {</div>
<div class="line">        @Override</div>
<div class="line">        <span class="keyword">public</span> <span class="keywordtype">int</span> compare(byte[] lhs, byte[] rhs) {</div>
<div class="line">            <span class="keywordflow">return</span> lhs.length - rhs.length;</div>
<div class="line">        }</div>
<div class="line">    }</div>
</div><!-- fragment --><p>Compares buffers by size </p>

</div>
</div>
<a class="anchor" id="abd8cd0d7462fc886099b2a1f4d8dd511"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">List&lt;byte[]&gt; com.ab.network.toolbox.ByteArrayPool.mBuffersByLastUse = new LinkedList&lt;byte[]&gt;()</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>The buffer pool, arranged both by last use and by buffer size </p>

</div>
</div>
<a class="anchor" id="a0b590097699829dea81659bf28ed5242"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">List&lt;byte[]&gt; com.ab.network.toolbox.ByteArrayPool.mBuffersBySize = new ArrayList&lt;byte[]&gt;(64)</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

</div>
</div>
<a class="anchor" id="a6e248b56d65802325d2208ea3e0dbef3"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">int com.ab.network.toolbox.ByteArrayPool.mCurrentSize = 0</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>The total size of the buffers in the pool </p>

</div>
</div>
<a class="anchor" id="a635c9ca5b29a0ce5f3ad8b6aadefec5e"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">final int com.ab.network.toolbox.ByteArrayPool.mSizeLimit</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>The maximum aggregate size of the buffers in the pool. Old buffers are discarded to stay under this limit. </p>

</div>
</div>
<hr/>该类的文档由以下文件生成:<ul>
<li>src/com/ab/network/toolbox/<a class="el" href="_byte_array_pool_8java.html">ByteArrayPool.java</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
生成于 2014年 十一月 6日 星期四 11:22:02 , 为 AndBase开发框架使用  &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.8
</small></address>
</body>
</html>
